package com.wgts.wgts.mvp.presenter.imp;

import com.wgts.wgts.control.labels.LabelData;
import com.wgts.wgts.mvp.model.ISearchActivityModel;
import com.wgts.wgts.mvp.presenter.ISearchActivityPersenter;
import com.wgts.wgts.mvp.view.ISearchActivityView;
import com.wgts.wgts.netmodle.HttpResultSubscriber;
import com.wgts.wgts.rxjava.MVPResultSubscriber;

import java.util.ArrayList;
import java.util.List;

/*
 *
 *
 *   data:2018/9/2710:09
 *
 */
public class SearchActivityPersenter implements ISearchActivityPersenter{
    private ISearchActivityModel model;
    private ISearchActivityView view;
    private List<LabelData> labelDataList;
    private List<LabelData> historyLabelData;

    public SearchActivityPersenter(ISearchActivityModel model, ISearchActivityView view) {
        this.model = model;
        this.view = view;
    }

    @Override
    public void HotSearchResult() {
        model.hotSearchResult(new HttpResultSubscriber<List<String>>() {
            @Override
            public void onSuccess(List<String> list) {
                labelDataList = new ArrayList<>();
                for (int i = 0; i < list.size(); i++){
                    LabelData labelData = new LabelData();
                    labelData.setName(list.get(i));
                    labelDataList.add(labelData);
                }
                view.hotSearchResult(labelDataList);
            }

            @Override
            public void _onError(int status, String msg) {

            }
        });
    }

    @Override
    public void WriteHistorySearch(String searchText) {
        model.WriteHistorySearch(searchText);
    }

    @Override
    public void getHistorySearch() {
        model.getHistorySearch(new MVPResultSubscriber<List<String>>() {
            @Override
            public void netx(List<String> list) {
                historyLabelData = new ArrayList<>();
                for (int i = 0; i < list.size(); i++){
                    LabelData labelData = new LabelData();
                    labelData.setName(list.get(i));
                    historyLabelData.add(labelData);
                }
                view.getHistorySearch(historyLabelData);
            }
        });
    }

    @Override
    public void clearHistorySearch() {
        model.clearHistorySearch(new MVPResultSubscriber<List<String>>() {
            @Override
            public void netx(List<String> list) {
                historyLabelData = new ArrayList<>();
                for (int i = 0; i < list.size(); i++){
                    LabelData labelData = new LabelData();
                    labelData.setName(list.get(i));
                    historyLabelData.add(labelData);
                }
                view.getHistorySearch(historyLabelData);
            }
        });
    }

}
